package com.aso114.project.util;

import android.util.Log;

import com.aso114.project.base.BaseApplication;

import java.io.IOException;
import java.util.HashSet;

import okhttp3.Interceptor;
import okhttp3.Request;

public class AddCookiesInterceptor implements Interceptor {

    @Override public okhttp3.Response intercept(Chain chain) throws IOException {

        Request.Builder builder = chain.request().newBuilder();
        HashSet<String> preferences = (HashSet)

                BaseApplication.getInstance().getSharedPreferences("config", BaseApplication.getInstance().MODE_PRIVATE).getStringSet("cookie", null);
        if (preferences != null) { for (String cookie : preferences)
        { builder.addHeader("Cookie", cookie);
        Log.v("OkHttp", "Adding Header: " + cookie); // This is done so I know which headers are being added; this interceptor is used after the normal logging of OkHttp

             } }

             return chain.proceed(builder.build()); } }


